/**
 * 
 */
package comm_test;


import java.io.IOException;
import java.net.UnknownHostException;


import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import comm.MoodType;
import comm.ServerMessage;

import comm.ServerSideMessage.Type;

/**
 * 
 * This class puts to the test the following:
 * 
 * --Verifies if all inspectors of the class ServerMessage are returning what is expected
 * 
 */
public class ServerMessage_Test {

	final ServerMessage newClientHasConnected = new ServerMessage("Coelho",null, Type.CLIENT_CONNECTED);
	final ServerMessage ClientHasDisconnected = new ServerMessage("Adriana",null, Type.CLIENT_DISCONNECTED);
	final ServerMessage moodishMessage = new ServerMessage("Shazix",MoodType.Creative.toString(), Type.MOODISH_MESSAGE);
	final ServerMessage friendship = new ServerMessage("Caterpillar","new friend", Type.FRIENDSHIP);
	final ServerMessage unfriendship = new ServerMessage("BAdoom","lost friend", Type.UNFRIENDSHIP);


	/**
	 * Verifies if the payload of the message is expected.
	 */	
	@Test
	public void test_isPayloadExpected(){
		//expected payloads
		Assert.assertNull(newClientHasConnected.getPayload());
		Assert.assertNull(ClientHasDisconnected.getPayload());
		Assert.assertEquals(MoodType.Creative.toString(), moodishMessage.getPayload());
		Assert.assertEquals("new friend", friendship.getPayload());
		Assert.assertEquals("lost friend", unfriendship.getPayload());
	}

	/**
	 * Verifies if the type of the message is expected.
	 */	
	@Test
	public void test_isTypeExpected(){
		//expected types
		Assert.assertEquals(Type.CLIENT_CONNECTED, newClientHasConnected.getType());
		Assert.assertEquals(Type.CLIENT_DISCONNECTED, ClientHasDisconnected.getType());
		Assert.assertEquals(Type.MOODISH_MESSAGE, moodishMessage.getType());
		Assert.assertEquals(Type.FRIENDSHIP, friendship.getType());
		Assert.assertEquals(Type.UNFRIENDSHIP, unfriendship.getType());
	}

	/**
	 * Verifies that the type of the message is not the expected one.
	 */	
	public void test_TypeIsNotExpected(){
		junit.framework.Assert.assertFalse("types should be different!",
				moodishMessage.getType().toString().equals(unfriendship.getType() ));
	}

	/**
	 * Verifies that Senders NickName match.
	 */	
	@Test
	public void test_isSendersNickNameExpected() throws UnknownHostException, IOException{
		Assert.assertEquals( "Coelho", newClientHasConnected.getClientNickname());
		Assert.assertEquals( "Adriana", ClientHasDisconnected.getClientNickname());
		Assert.assertEquals( "Shazix", moodishMessage.getClientNickname());
		Assert.assertEquals( "Caterpillar", friendship.getClientNickname());
		Assert.assertEquals( "BAdoom", unfriendship.getClientNickname());
	}
	/**
	 * Verifies that Senders NickName does not match.
	 */		
	@Test
	public void test_SendersNickNameNoMatch() throws UnknownHostException, IOException{
		Assert.assertFalse( "Nicknames shouldnt match!","Catia".equals(newClientHasConnected.getClientNickname()));
	}
}
